﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:local="clr-namespace:ColorPicker"
>
	<local:ByteDoubleConverter
		x:Key="byteDoubleConverter"
	/>

	<local:ColorBrushConverter
		x:Key="colorBrushConverter"
	/>

	<Style
		x:Key="colorSliderStyle"
		TargetType="{x:Type Slider}"
	>
		<Setter Property="Minimum" Value="0"/>
		<Setter Property="Maximum" Value="255"/>
		<Setter Property="SmallChange" Value="1"/>
		<Setter Property="LargeChange" Value="51"/>
		<Setter Property="IsMoveToPointEnabled" Value="True"/>
		<Setter Property="Orientation" Value="Horizontal"/>
	</Style>

	<Style TargetType="{x:Type local:ColorPicker}">
		<Setter Property="HorizontalAlignment" Value="Center"/>
		<Setter Property="VerticalAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:ColorPicker}">
					<Grid>
						<Grid.RowDefinitions>
							<RowDefinition/>
							<RowDefinition/>
							<RowDefinition/>
							<RowDefinition/>
						</Grid.RowDefinitions>
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto"/>
							<ColumnDefinition Width="*"/>
							<ColumnDefinition Width="Auto"/>
							<ColumnDefinition Width="Auto"/>
						</Grid.ColumnDefinitions>

						<TextBlock
							Grid.Row="0" Grid.Column="0"
							Text="Alpha:"
						/>
						<TextBlock
							Grid.Row="1" Grid.Column="0"
							Text="Red:"
						/>
						<TextBlock
							Grid.Row="2" Grid.Column="0"
							Text="Green:"
						/>
						<TextBlock
							Grid.Row="3" Grid.Column="0"
							Text="Blue:"
						/>

						<Slider
							Grid.Row="0" Grid.Column="1"
							Style="{StaticResource colorSliderStyle}"
							Value="{Binding Path=Alpha, Converter={StaticResource byteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
						/>
						<Slider
							Grid.Row="1" Grid.Column="1"
							Style="{StaticResource colorSliderStyle}"
							Value="{Binding Path=Red, Converter={StaticResource byteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
						/>
						<Slider
							Grid.Row="2" Grid.Column="1"
							Style="{StaticResource colorSliderStyle}"
							Value="{Binding Path=Green, Converter={StaticResource byteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
						/>
						<Slider
							Grid.Row="3" Grid.Column="1"
							Style="{StaticResource colorSliderStyle}"
							Value="{Binding Path=Blue, Converter={StaticResource byteDoubleConverter}, RelativeSource={RelativeSource TemplatedParent}}"
						/>

						<TextBox
							Grid.Row="0" Grid.Column="2"
							Width="32"
							Text="{Binding Path=Alpha, RelativeSource={RelativeSource TemplatedParent}}"
						/>
						<TextBox
							Grid.Row="1" Grid.Column="2"
							Width="32"
							Text="{Binding Path=Red, RelativeSource={RelativeSource TemplatedParent}}"
						/>
						<TextBox
							Grid.Row="2" Grid.Column="2"
							Width="32"
							Text="{Binding Path=Green, RelativeSource={RelativeSource TemplatedParent}}"
						/>
						<TextBox
							Grid.Row="3" Grid.Column="2"
							Width="32"
							Text="{Binding Path=Blue, RelativeSource={RelativeSource TemplatedParent}}"
						/>

						<Border
							Grid.Row="0" Grid.RowSpan="4" Grid.Column="3"
							BorderBrush="Black" BorderThickness="1"
						>
							<Rectangle
								Width="50"
								Fill="{Binding Path=Color, Converter={StaticResource colorBrushConverter}, RelativeSource={RelativeSource TemplatedParent}}"
							/>
						</Border>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>
